package com.zl.smartmall.library.po;

import java.util.ArrayList;
import java.util.List;

import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Property;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 商品列表
 * 
 * @author 陈希然
 * 
 */
public class ActivitiesCommoditiesInfo extends BaseActivitiesInfo  {

	@Id
	private int id;
	@Property
	private int shopId;
	@Property
	private int brandId;
	@Property
	private int classifyId;
	@Property
	private int productId;
	@Property
	private String productTitle;
	@Property
	private String picture;
	@Property
	private String brandName;
	@Property
	private String shopName;
	private String[] label;// 促销、免邮
	@Property
	private int width;
	@Property
	private int height;
	@Property
	private int inventoryNum;
	@Property
	private int saleNum;
	@Property
	private double originalCost;
	@Property
	private double currentCost;

	// "ptype": 0,
	// "jifen": 0,
	// "isHot": 1,
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getShopId() {
		return shopId;
	}

	public void setShopId(int shopId) {
		this.shopId = shopId;
	}

	public int getBrandId() {
		return brandId;
	}

	public void setBrandId(int brandId) {
		this.brandId = brandId;
	}

	public int getClassifyId() {
		return classifyId;
	}

	public void setClassifyId(int classifyId) {
		this.classifyId = classifyId;
	}

	public int getProductId() {
		return productId;
	}

	public void setProductId(int productId) {
		this.productId = productId;
	}

	public String getProductTitle() {
		return productTitle;
	}

	public void setProductTitle(String productTitle) {
		this.productTitle = productTitle;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public String getBrandName() {
		return brandName;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}

	public String getShopName() {
		return shopName;
	}

	public void setShopName(String shopName) {
		this.shopName = shopName;
	}

	public String[] getLabel() {
		return label;
	}

	public void setLabel(String[] label) {
		this.label = label;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getInventoryNum() {
		return inventoryNum;
	}

	public void setInventoryNum(int inventoryNum) {
		this.inventoryNum = inventoryNum;
	}

	public int getSaleNum() {
		return saleNum;
	}

	public void setSaleNum(int saleNum) {
		this.saleNum = saleNum;
	}

	public double getOriginalCost() {
		return originalCost;
	}

	public void setOriginalCost(double originalCost) {
		this.originalCost = originalCost;
	}

	public double getCurrentCost() {
		return currentCost;
	}

	public void setCurrentCost(double currentCost) {
		this.currentCost = currentCost;
	}
	
	private static ActivitiesCommoditiesInfo parse(JSONObject jsonObject) throws JSONException {
		if(jsonObject != null && jsonObject.length() > 0) {
			ActivitiesCommoditiesInfo commoditiesInfo = new ActivitiesCommoditiesInfo();
			commoditiesInfo.brandId = jsonObject.getInt("brand_id");
			commoditiesInfo.brandName =  jsonObject.getString("brand_name");
			commoditiesInfo.classifyId = jsonObject.getInt("classify_id");
			commoditiesInfo.currentCost = jsonObject.getDouble("sale_price");
			commoditiesInfo.height = jsonObject.getInt("height");
			commoditiesInfo.inventoryNum = jsonObject.getInt("num");
			commoditiesInfo.originalCost = jsonObject.getDouble("tag_price");
			commoditiesInfo.picture = jsonObject.getString("pic");
			commoditiesInfo.productId = jsonObject.getInt("product_id");
			commoditiesInfo.productTitle = jsonObject.getString("product_title");
			commoditiesInfo.saleNum = jsonObject.getInt("sale_num");
			commoditiesInfo.shopId = jsonObject.getInt("shop_id");
			commoditiesInfo.shopName = jsonObject.getString("shop_name");
			commoditiesInfo.width = jsonObject.getInt("width");
	        JSONArray labelArray = jsonObject.getJSONArray("promotion");
			commoditiesInfo.label = new String[labelArray.length()];
	        for(int i = 0; i < labelArray.length(); i++) {
	        	commoditiesInfo.label[i] = labelArray.getJSONObject(i).getString("name");
	        }
	        commoditiesInfo.activitiesInfoType = ActivitiesInfoType.TYPE_COMMODITIES_ITEM;
	        
	        return commoditiesInfo;
		}
		return null;
	}

	public static List<ActivitiesCommoditiesInfo> parse(JSONArray jsonArray) throws JSONException {
		List<ActivitiesCommoditiesInfo> commoditiesInfos = new ArrayList<ActivitiesCommoditiesInfo>();
		for(int i = 0; jsonArray != null && i < jsonArray.length(); i++) {
			JSONObject jsonObject =  jsonArray.getJSONObject(i);
			ActivitiesCommoditiesInfo commoditiesInfo = parse(jsonObject);
			if(commoditiesInfo != null) {
				commoditiesInfos.add(commoditiesInfo);
			}
		}
		
		return commoditiesInfos;
	}
}
